package com.kuang.demo.service.wx;

import com.github.pagehelper.PageHelper;
import com.kuang.demo.bean.wx.FootPrint;
import com.kuang.demo.mapper.GoodsMapper;
import com.kuang.demo.mapper.acg.UserMapper;
import com.kuang.demo.mapper.wx.WXFootPrintMapper;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class FootPrintServiceImpl implements FootPrintService {
    @Autowired
    WXFootPrintMapper footprintMapper;
    @Autowired
    UserMapper userMapper;
    @Override
    public List<FootPrint.FootprintListBean> footprintList(int page, int size) {
//        int id = WXSearchUserId.id();
        Subject subject= SecurityUtils.getSubject();
        String  userName = (String) subject.getPrincipal();
        int id = userMapper.selectUserId(userName);
        PageHelper.startPage(page,size);
        List<Integer> integers= footprintMapper.selectGoodsIdByUserId(id);
        List<FootPrint.FootprintListBean> footprintList = new ArrayList<>();
        for (Integer integer : integers) {
            FootPrint.FootprintListBean e = footprintMapper.selectfootprintList(integer);
            footprintList.add(e);
        }
        return footprintList;
    }

    @Override
    public int footprintListPages(int size) {
        Subject subject= SecurityUtils.getSubject();
        String  userName = (String) subject.getPrincipal();
        int id = userMapper.selectUserId(userName);
        List<Integer> integers= footprintMapper.selectGoodsIdByUserId(id);
        return integers.size();
    }

    @Override
    public void delete(Integer id) {
        footprintMapper.deletById(id);
    }
}
